{extend name="public/container"}
{block name="title"}{if $type}我的收藏{else}我的课程{/if}{/block}
{block name='head_top'}
<style>
    .mask .box {
        position: relative;
    }

    .mask .box .iconfont {
        color: #ffffff;
        font-size: 0.4rem;
        left: 50%;
        margin-left: -0.2rem;
        bottom: 0.3rem
    }

    .public_list .item .text {
        -webkit-align-self: flex-start;
        align-self: flex-start;
    }

    .loading {
        font-size: .4rem;
        text-align: center;
        color: #999;
    }

    .loaded {
        font-size: .28rem;
        line-height: .72rem;
        text-align: center;
        color: #999;
    }

    .nothing {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 4.14rem;
        height: 3.36rem;
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
</style>
{/block}
{block name="content"}
<div v-cloak id="app">
    <div class="favorite">
        <a v-for="item in makeGradeList" :key="item.id" :href="item.path" class="item">
            <div class="image">
                <img :src="item.image">
                <div class="label">{{type==1 ?  item.types :  item.type}}</div>
            </div>
            <div class="text">
                <div class="name">{{ item.title }}</div>
                <div class="label">
                    <template v-for="(itm, idx) in item.label">
                        <span v-if="idx < 2" :key="idx">{{ itm }}</span>
                    </template>
                </div>
                <div class="price">
                    <template>
                        <div v-if="item.money === '0.00'" class="free">免费</div>
                        <div v-else class="money">¥<span>{{ item.money }}</span></div>
                        <div v-if="item.types!=4" class="total">共{{item.count}}节</div>
                    </template>
                </div>
            </div>
        </a>
        <div v-show="loading" class="loading">
            <span class="fa fa-spinner"></span>
        </div>
        <div v-if="loadend && page > 2" class="loaded">已全部加载</div>
        <div v-if="!gradeList.length && !loading" >
            {if $type}
            <img class="nothing"  src="/wap/first/zsff/images/no_collection.png">
            {else}
            <img class="nothing"  src="/wap/first/zsff/images/no_data_available.png">
            {/if}
        </div>
        <div style="height: 1.2rem"></div>
    </div>
    <div class="my-course" ref="app">
        <enter :appear="appear" @change="changeVal" :url="url" :site_name="site_name"></enter>
        <div class="mask" @touchmove.prevent style="z-index: 100;" v-show="isfollow">
            <h4>立即绑定微信公众号用户</h4>
            <div class="code">
                <img :src="codeUrl" class="image" alt="">
            </div>
            <div class="button" @click="skip">跳过</div>
        </div>
        {if !$subscribe && !empty($userInfo)}
        <div class="publicFollow acea-row row-between-wrapper" style="bottom: 1.2rem;">
            <div>关注公众号"{$Auth_site_name}"，看课更方便</div>
            <div class="follow acea-row row-center-wrapper" @click=" is_code = true ">关注</div>
        </div>
        <div class="groupCode" v-if="is_code" v-cloak="" @click="clone">
            <div class="ewmCon">
                <div class="code"><img :src="wechat_qrcode"></div>
                <div class="codeTip">长按扫一扫<br>关注微信公众号<br>立马学习</div>
                <div class="iconfont icon-guanbi"></div>
            </div>
        </div>
        <div class="mask" style="align-items:center;display: flex;" v-if="is_code" @click="clone"></div>
        <div style="height: 1.0rem"></div>
        {/if}
    </div>
    <quick-menu></quick-menu>
</div>
{/block}
{block name="foot"}
<script>
    var wechat_qrcode = '{$subscribeQrcode}', type = '{$type}',site_name = '{$Auth_site_name}';
    require(['vue', 'helper', 'store', 'special-type', '{__WAP_PATH}zsff/js/enter.js','quick'], function (Vue, $h, storeApi, specialType) {
        new Vue({
            el: '#app',
            data: {
                site_name:site_name,
                navlist: [{title: '我的课程'}, {title: '我的收藏'}],
                loadend: false,
                loading: false,
                active: 0,
                type: type,
                gradeList: [],
                min: 2,
                page: 1,
                limit: 10,
                count: 0,
                codeUrl: '',
                appear: true,
                isfollow: false,
                url: $h.U({c: 'login', a: 'phone_check'}),
                wechat_qrcode: wechat_qrcode,
                is_code: $h.getCookie('QRCODE') ? false : true,
            },
            computed: {
                makeGradeList: function () {
                    return this.gradeList.map(function (value) {
                        if(type==1){
                            value.types = specialType[value.type];
                        }
                        value.path = $h.U({c: 'special', a: 'details', q: { id: value.s_id }}) + (this.active == 0 ? '#tash' : '');
                        return value;
                    });
                }
            },
            watch: {
                active: function () {
                    this.$set(this, 'gradeList', []);
                    this.page = 1;
                    this.loadend = false;
                    this.getGradeList();
                }
            },
            mounted: function () {
                var that = this;
                storeApi.baseGet($h.U({c: 'index', a: 'login_user'}), function (res) {
                    that.getGradeList();
                }, function () {
                    that.appear = false;
                });
                if (type == 1) {
                    this.active = 1;
                }
            },
            methods: {
                clone: function () {
                    this.is_code = false;
                    $h.setCookie('QRCODE', 1, 1576237948);
                },
                skip: function () {
                    this.isfollow = false;
                    this.appear = true;
                    setTimeout(function () {
                        window.location.reload();
                    }, 800);
                },
                loginClose: function () {
                    this.appear = true;
                },
                logComplete: function (data) {
                    var that = this;
                    if (!data.isfollow) {
                        this.codeUrl = data.url;
                        this.isfollow = true;
                        var qcode_id = data.qcode_id;
                        var interval = setInterval(function () {
                            app.baseGet($h.U({c: 'index', a: 'qcode_login', q: {qcode_id: qcode_id}}), function (res) {
                                clearInterval(interval);
                                that.isfollow = false;
                                setTimeout(function () {
                                    window.location.reload();
                                }, 800);
                            }, null, true);
                        }, 1000);
                    } else {
                        that.appear = true;
                        window.location.reload();
                    }
                },
                //所有插件回调处理事件
                changeVal: function (opt) {
                    if (typeof opt != 'object') opt = {};
                    var action = opt.action || '';
                    var value = opt.value || '';
                    this[action] && this[action](value);
                },
                getTashUrl: function (id) {
                    return $h.U({c: 'special', a: 'details', q: {id: id}}) + (this.active == 0 ? '#tash' : '');
                },
                EventUtil: function () {
                    var that = this;
                    that.$nextTick(function () {
                        $h.EventUtil.listenTouchDirection(document, function () {
                            that.loading == false && that.getGradeList();
                        }, false);
                    })
                },
                getGradeList: function () {
                    var that = this;
                    if (that.loading) return;
                    if (that.loadend) return;
                    that.loading = true;
                    storeApi.baseGet($h.U({
                        c: 'special',
                        a: 'get_grade_list',
                        q: {type: that.active, page: that.page, limit: that.limit}
                    }), function (res) {
                        var list = res.data.data.list;
                        that.gradeList.push.apply(this.gradeList, list);
                        this.loadend = list.length < this.limit;
                        this.page = res.data.data.page;
                        this.loading = false;
                        this.$set(this, 'gradeList', this.gradeList);
                        this.EventUtil();
                    }.bind(this), function () {
                        that.loading = false;
                    });
                },
            }
        });
    })
</script>
{/block}
